// JavaScript Document
var rowid = "row_id";            //tr id
var zoneid = "zone_id";		// zone name td id
var stateid = "state_id";
var cancel = "";// disable enable span id
var current_editid="";

function Inint_AJAX() 
{
	try 
	{ 
		return new ActiveXObject("Msxml2.XMLHTTP");  
	} 
	catch(e) 
	{} //IE
	try 
	{ 
		return new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	catch(e) {} //IE
	try 
	{ 
		return new XMLHttpRequest(); 
	} catch(e) {} //Native Javascript
	alert("XMLHttpRequest not supported");
	return null;
};
		
function edit_zone(id,value) 
{
	$(".zone_row").fadeOut("slow");
	$("#"+rowid+"_"+id).fadeIn("slow");
	cancel = document.getElementById(rowid+"_"+id).innerHTML;
	
	var editmode = document.getElementById(zoneid+"_" + id);
	
	editmode.innerHTML ="<input type='text' id='zone_new_name' size='30' value='"+ value +"' />&nbsp;<input type='button' value='Save' onClick=\" save_changes('zone_new_name','"+id+"'); \" />";
	current_editid=id;
	editmode.innerHTML +="<input type='button' value='Cancel' onClick=\" default_row('"+id+"'); \" />";
	

}
function default_row(id){
	$(".zone_row").fadeIn("slow");
	document.getElementById(rowid+"_"+id).innerHTML = cancel;
}
function save_changes(new_name,id){
	var zone_new_name  = document.getElementById(new_name);
	var row_change = document.getElementById(rowid+"_"+id);
	row_change.innerHTML = "<td colspan='4' align='center'><b>Saving.....</b></td>";
	
	var http = Inint_AJAX();
	http.onreadystatechange = function () 
	{ 	
		if(http.readyState == 4 && http.status == 200) {
		row_change.innerHTML = http.responseText;
		
		$(".zone_row").fadeIn("slow");
		}
	};
	http.open("post", "call_ajax_zone_change.php?name="+escape(zone_new_name.value)+"&&id="+id,true); 
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); // set Header
	http.send(null); 

}

function status_handler(value,id) {
	var changetag = document.getElementById(stateid+"_"+id);
	changetag.innerHTML ="<font style='font-size: 8.5pt' face='Verdana' >Loading....</font>";
	var http = Inint_AJAX();
	http.onreadystatechange = function () 
	{ 	
		if(http.readyState == 4 && http.status == 200) {
		changetag.innerHTML = http.responseText;
		}
	};
	http.open("post", "call_ajax_zone_change.php?status=" + value + "&&id=" + id,true); 
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); // set Header
	http.send(null); 
	

}

function add_zone(value,msg) {
var zone_name = document.getElementById(value);
	if(zone_name.value == "") {
	$("#"+msg).html("<font color='red'>zone name is required</font>");
	zone_name.focus();
	return false;
	}
	else {
		var http = Inint_AJAX();
		http.onreadystatechange = function () 
		{ 	
			if(http.readyState == 4 && http.status == 200) {
			$("#table1 > #content_zone:First").prepend(http.responseText);
			$("#zone_msg").html("zone is added successfully");
			$("#add_form").toggle(250);
			}
		};
		http.open("post", "call_ajax_zone_change.php?add_name="+escape(zone_name.value),true); 
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); // set Header
		http.send(null); 
		
	return false;
	}
}



